/*
 * PACKAGE NAME: com.jodinfo.outmirror.api.controlwidget.controller
 * FILE    NAME: ControlWidgetDaoImpl.java
 * COPYRIGHT: Copyright(c) © 2016 heroj Company Ltd. All Rights Reserved
 */ 
package com.jodinfo.outmirror.api.controlwidget.controller;

import java.math.BigInteger;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.fastjson.JSON;
import com.hero.common.web.context.UserContext;
import com.hero.core.constant.SysConstant;
import com.hero.core.entity.ResponseEntity;
import com.jodinfo.outmirror.api.controlwidget.entity.ControlWidgetEntity;
import com.jodinfo.outmirror.api.controlwidget.service.ControlWidgetBizService;



@Controller
@RequestMapping(value = "/ControlWidgetAdmin")
public class ControlWidgetController  {
	
@Resource(name="controlWidgetBizService")
private ControlWidgetBizService controlWidgetBizService;
/**
*  list数据源
* 
* */
@RequestMapping(value = "/List")
@ResponseBody
public String controlWidgetList(ControlWidgetEntity controlWidgetEntity) {
	if(controlWidgetEntity==null){
		controlWidgetEntity = new ControlWidgetEntity();
		controlWidgetEntity.setPageIndex(SysConstant.DEFAULT_PAGEINDEX);
		controlWidgetEntity.setPageSize(SysConstant.DEFAULT_PAGESIZE);
	}
	controlWidgetEntity.setCurrentUser(UserContext.getUser());
	String str = controlWidgetBizService.queryListForPageControlWidget(controlWidgetEntity);
	return str;
}
/**
*  list数据源
* 
* */
@RequestMapping(value = "/queryAllControlWidgetEntity.json")
@ResponseBody
public String queryAllControlWidgetEntity(ControlWidgetEntity controlWidgetEntity) {
	controlWidgetEntity.setCurrentUser(UserContext.getUser());
	String str = controlWidgetBizService.queryAllControlWidget(controlWidgetEntity);
	return str;
}
/**
* ControlWidgetEntity List页面
* 
* */
@RequestMapping(value = "/ListPage")
public ModelAndView controlWidgetListPage(ControlWidgetEntity controlWidgetEntity,HttpServletRequest request) {
	
	return new ModelAndView(returnPath("controlWidgetList"));
}
/**
* ControlWidgetEntity详细页 
* 
* */
@RequestMapping(value = "/EditPage")
public ModelAndView controlWidgetEditPage(ControlWidgetEntity controlWidgetEntity) {
	
	return new ModelAndView(returnPath("controlWidgetAdd"));
}
/**
 * 查询ControlWidgetEntity
 * 
 * */
@RequestMapping(value = "/queryByID")
public @ResponseBody String findControlWidgetData(HttpServletRequest request) {
	String id = request.getParameter("id");
	ControlWidgetEntity controlWidgetEntity =  controlWidgetBizService.queryById(new BigInteger(id));
	return JSON.toJSONString(controlWidgetEntity); 
}

/**
 * 保存或更新ControlWidget 
 * 
 * */
@RequestMapping(value = "/saveControlWidget")
public @ResponseBody String saveControlWidgetData(@RequestBody ControlWidgetEntity controlWidgetEntity) {
	ResponseEntity rs = null;
	if(controlWidgetEntity!=null){
		controlWidgetEntity.setCurrentUser(UserContext.getUser());
		if(controlWidgetEntity.getId()!=null){
			rs = controlWidgetBizService.updateControlWidget(controlWidgetEntity);
		}else{
			rs = controlWidgetBizService.addControlWidget(controlWidgetEntity);
		}
	}
	return JSON.toJSONString(rs);
}
/**
 * 导出ControlWidgetEntity
 * @author shensu
 * @date 2015-7-09  下午2:13:28
 * @return
 */
@RequestMapping(value = "/exportControlWidgetExcel")
public void exportControlWidgetExcel(ControlWidgetEntity controlWidgetEntity,HttpServletResponse response) {
		controlWidgetBizService.exportControlWidget(controlWidgetEntity, response);
}
/**
 * 定义
 * 
 */
private final String MODULE_PATH = "/controlwidget/";

//返回路径
private String returnPath(String jspName) {
	return MODULE_PATH + jspName;
}
}
